/*
 * @Author: 江舟 jijiangzhou@recycloud.cn
 * @Date: 2024-03-28 20:42:32
 * @LastEditors: 江舟 jijiangzhou@recycloud.cn
 * @LastEditTime: 2024-05-28 17:16:51
 * @FilePath: \vite-project\src\components\common\CountDown.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import useCacheTimeCountDown from 'hooks/common/useCacheTimeCountDown';
import { Button } from 'antd';
import React from 'react';

const CountDown = (props: {
    loading: boolean | { delay?: number | undefined } | undefined;
    onSend: (arg0: (d?: number) => void) => void;
}) => {
    // hook
    const { timeLeft, reStart } = useCacheTimeCountDown(60);
    return timeLeft ? (
        <Button size='large' disabled className='w-120px'>
            {timeLeft}秒
        </Button>
    ) : (
        <Button
            loading={props?.loading}
            type='primary'
            size='large'
            ghost
            onClick={() => props.onSend(reStart)}
            className='w-120px'
        >
            获取验证码
        </Button>
    );
};

export default CountDown;
